from BasePage import BasePage
import time
class SurprisePage(BasePage):
    # 购买翻译vip
    # 点击我的按钮
    _me = (BasePage.ID, 'com.zoneyet.lovehottie:id/layout_me')
    # 点击字符图标
    _char = (BasePage.ID, 'com.zoneyet.lovehottie:id/rl_me_translate')
    # 选择10min翻译时长
    _select10min = (BasePage.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.ScrollView/android.widget.LinearLayout/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[1]/android.widget.RelativeLayout')
    # 点击支付按钮
    _pay = (BasePage.ID, 'com.zoneyet.lovehottie:id/tv_trans_pay')
    # 点击购买按钮
    _buy = (BasePage.ID, 'com.zoneyet.lovehottie:id/btn_translate_pay')
    # 购买失败
    _buyfail = (BasePage.ID, 'com.zoneyet.lovehottie:id/cancel')
    # 返回到上一个页面
    _back = (BasePage.ID, 'com.zoneyet.lovehottie:id/iv_back')
    # 点击购买完成按钮
    _buysuccess = (BasePage.ID, 'com.zoneyet.lovehottie:id/btn_paysucess_finish')
    # 购买翻译包
    # 点击翻译包按钮
    _package = (BasePage.ID, 'com.zoneyet.lovehottie:id/tv_tab_translate_package')
    # 选择500字符档位
    _500package = (BasePage.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.ScrollView/android.widget.LinearLayout/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[1]/android.widget.RelativeLayout')
    # 跳转到消息页面
    _message = (BasePage.ID, 'com.zoneyet.lovehottie:id/layout_chat')
    # 选择第一个用户
    _firstfriend = (BasePage.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[3]/android.widget.RelativeLayout/android.view.ViewGroup/android.view.ViewGroup/android.widget.ImageView')
    # 点击给他人惊喜
    _surprised = (BasePage.ID, 'com.zoneyet.lovehottie:id/btn_upgrade')
    # 选择翻译畅聊沟通无障碍档位
    _translateGear = (BasePage.ID, 'com.zoneyet.lovehottie:id/rl_trans')
    # 选择会员升级更贴近彼此档位
    _Upgradeher = (BasePage.ID, 'com.zoneyet.lovehottie:id/rl_vip')
    # 点击会员升级图标
    _upgrade = (BasePage.ID, 'com.zoneyet.lovehottie:id/ll_mine_vip')
    # 选择mini会员
    _mini = (BasePage.ID, 'com.zoneyet.lovehottie:id/tv_tab_mini')
    # 选择高级会员
    _senior = (BasePage.ID, 'com.zoneyet.lovehottie:id/tv_tab_svip')
    # 选择vip会员
    _vip = (BasePage.ID, 'com.zoneyet.lovehottie:id/tv_tab_vip')
    # 当前会员等级
    _grade = (BasePage.ID, 'com.zoneyet.lovehottie:id/me_vip_remain')
    # 用户金币余额
    _balance = (BasePage.ID, 'com.zoneyet.lovehottie:id/tv_me_wallet_balance')

    def own_Translation_success(self):
        # 自己购买翻译vip
        time.sleep(1)
        self.click(self._me)
        time.sleep(1)
        self.click(self._char)
        self.driver.implicitly_wait(3)
        self.click(self._select10min)
        self.driver.implicitly_wait(3)
        self.click(self._pay)
        time.sleep(1)
        self.swipe_up(count=1)
        time.sleep(1)
        self.click(self._buy)
        time.sleep(1)
        try:
            # 点击充值弹框里的取消按钮
            self.click(self._buyfail)
            print("用户自己购买翻译vip失败，请手动添加金币，再次执行！")
            # 返回到上一个页面
            self.click(self._back)
        except:
            self.click(self._buysuccess)
            print("用户自己购买翻译vip成功！")
        time.sleep(3)

        # 自己购买翻译包
        self.click(self._package)
        time.sleep(2)
        self.click(self._500package)
        time.sleep(1)
        self.click(self._pay)
        time.sleep(1)
        self.swipe_up(count=1)
        time.sleep(2)
        self.click(self._buy)
        time.sleep(1)
        try:
            # 点击充值弹框里的取消按钮
            self.click(self._buyfail)
            print("用户自己购买翻译包失败，请手动添加金币，再次执行！")
            # 返回到上一个页面
            self.click(self._back)
            time.sleep(1)
            # 返回到我的页面
            self.click(self._back)
        except:
            self.click(self._buysuccess)
            print("用户自己购买翻译包成功！")
            self.click(self._back)
        time.sleep(1)
    def own_upgrade_success(self):
        self.click(self._me)
        time.sleep(1)
        grade = self.find_element(self._grade).text
        balance = float(self.find_element(self._balance).text)
        time.sleep(1)
        if grade=='会员' or grade=='Mini':
            if balance  > 9.9:
                # 给自己升级会员
                self.click(self._upgrade)
                time.sleep(1)
                # 购买迷你会员
                self.click(self._mini)
                self.click(self._pay)
                time.sleep(1)
                self.swipe_up(count=1)
                time.sleep(2)
                self.click(self._buy)
                time.sleep(1)
                self.click(self._buysuccess)
                self.click(self._back)
                time.sleep(2)
                balance1 = float(self.find_element(self._balance).text)
                time.sleep(2)
                if balance1  > 50:
                    self.click(self._upgrade)
                    time.sleep(1)
                    # 购买高级会员
                    self.click(self._senior)
                    time.sleep(1)
                    self.click(self._pay)
                    time.sleep(1)
                    self.swipe_up(count=1)
                    time.sleep(2)
                    self.click(self._buy)
                    time.sleep(1)
                    self.click(self._buysuccess)
                    self.click(self._back)
                    time.sleep(2)
                    balance2 = float(self.find_element(self._balance).text)
                    time.sleep(2)
                    if balance2 > 499:
                        self.click(self._upgrade)
                        time.sleep(2)
                        # 购买vip会员
                        self.click(self._vip)
                        time.sleep(1)
                        self.click(self._pay)
                        time.sleep(1)
                        self.swipe_up(count=1)
                        time.sleep(2)
                        self.click(self._buy)
                        time.sleep(1)
                        self.click(self._buysuccess)
                        self.click(self._back)
                    else:
                        print("用户升级vip会员时，金币不足，请手动添加金币，重新执行脚本！")
                else:
                    print("用户升级高级和vip会员时，金币不足，请手动添加金币，重新执行脚本！")
            else:
                print("用户升级mini会员时，金币不足，请手动添加金币，重新执行脚本！")
        if grade=='高级':
            if balance > 50:
                self.click(self._upgrade)
                time.sleep(1)

                # 购买高级会员
                self.click(self._senior)
                self.click(self._pay)
                time.sleep(1)
                self.swipe_up(count=1)
                time.sleep(1)
                self.click(self._buy)
                time.sleep(1)
                self.click(self._buysuccess)
                self.click(self._back)
                time.sleep(2)
                balance1 = float(self.find_element(self._balance).text)
                time.sleep(2)
                if balance1 > 499:
                    self.click(self._upgrade)
                    time.sleep(1)
                    # 购买高级会员
                    self.click(self._vip)
                    time.sleep(1)
                    self.click(self._pay)
                    time.sleep(1)
                    self.swipe_up(count=1)
                    time.sleep(2)
                    self.click(self._buy)
                    time.sleep(1)
                    self.click(self._buysuccess)
                    self.click(self._back)
                else:
                    print("用户升级vip会员时，金币不足，请手动添加金币，重新执行脚本！")
            else:
                print("用户升级高级和vip会员时，金币不足，请手动添加金币，重新执行脚本！")
        if grade=='VIP':
            if balance > 499:
                self.click(self._upgrade)
                time.sleep(1)

                # 购买vip会员
                self.click(self._vip)
                self.click(self._pay)
                time.sleep(1)
                self.swipe_up(count=1)
                time.sleep(1)
                self.click(self._buy)
                time.sleep(1)
                self.click(self._buysuccess)
                self.click(self._back)
            else:
                print("用户升级vip会员时，金币不足，请手动添加金币，重新执行脚本！")
        time.sleep(1)
    def other_Translation_success(self):
        # 跳转到我的消息页面
        time.sleep(4)
        self.click(self._message)
        self.driver.implicitly_wait(5)
        self.click(self._firstfriend)
        time.sleep(1)
        self.click(self._surprised)
        time.sleep(1)
        self.click(self._translateGear)
        self.click(self._select10min)
        self.driver.implicitly_wait(3)
        self.click(self._pay)
        time.sleep(1)
        self.swipe_up(count=1)
        time.sleep(1)
        self.click(self._buy)
        time.sleep(1)
        try:
            # 点击充值弹框里的取消按钮
            self.click(self._buyfail)
            print("给他人购买翻译vip失败，请手动添加金币，再次执行！")
            # 返回到上一个页面
            self.click(self._back)
            time.sleep(1)
            # 返回到给她惊喜页面
            self.click(self._back)
        except:
            self.click(self._buysuccess)
            print("给他人购买翻译vip成功！")
        time.sleep(3)
        self.click(self._translateGear)
        time.sleep(2)
        self.click(self._package)
        time.sleep(1)
        self.click(self._500package)
        time.sleep(1)
        self.click(self._pay)
        time.sleep(1)
        self.swipe_up(count=1)
        time.sleep(2)
        self.click(self._buy)
        time.sleep(1)
        try:
            # 点击充值弹框里的取消按钮
            self.click(self._buyfail)
            print("给他人购买翻译包失败，请手动添加金币，再次执行！")
            # 返回到上一个页面
            self.click(self._back)
            time.sleep(1)
            # 返回到我的页面
            self.click(self._back)
        except:
            self.click(self._buysuccess)
            print("给他人购买翻译包成功！")
        time.sleep(1)
    def other_upgrade_success(self):
        time.sleep(1)
        # 点击会员升级
        self.click(self._Upgradeher)
        time.sleep(3)
        # 1。。。。。。。。。。。。。。。。。。。。。。。。。。。。购买迷你会员
        self.click(self._mini)
        time.sleep(1)
        self.click(self._pay)
        time.sleep(1)
        self.swipe_up(count=1)
        time.sleep(1)
        self.click(self._buy)
        time.sleep(2)
        try:
            # 点击充值弹框里的取消按钮
            self.click(self._buyfail)
            print("给他人升级mini会员失败，请手动添加金币，再次执行！")
            # 返回到上一个页面
            self.click(self._back)
        except:
            try:
                self.click(self._buysuccess)
                time.sleep(1)
                # 点击会员升级
                self.click(self._Upgradeher)
            except:
                # print("不能降级购买！")
                # 返回到上一个页面
                self.click(self._back)
        time.sleep(3)
        # 2。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。购买高级会员
        self.click(self._senior)
        time.sleep(1)
        self.click(self._pay)
        time.sleep(1)
        self.swipe_up(count=1)
        time.sleep(2)
        self.click(self._buy)
        time.sleep(1)
        try:
            # 点击充值弹框里的取消按钮
            self.click(self._buyfail)
            print("给他人升级高级会员失败，请手动添加金币，再次执行！")
            # 返回到上一个页面
            self.click(self._back)
        except:
            try:
                self.click(self._buysuccess)
                time.sleep(1)
                # 点击会员升级
                self.click(self._Upgradeher)
            except:
                print("不能降级购买！")
                # 返回到上一个页面
                self.click(self._back)
        # 3。。。。。。。。。。。。。。。。。。。。。。。。。。。。购买vip会员
        time.sleep(3)
        self.click(self._vip)
        time.sleep(1)
        self.click(self._pay)
        time.sleep(1)
        self.swipe_up(count=1)
        time.sleep(2)
        self.click(self._buy)
        time.sleep(1)
        try:
            # 点击充值弹框里的取消按钮
            self.click(self._buyfail)
            print("给他人升级vip会员失败，请手动添加金币，再次执行！")
            # 返回到上一个页面
            self.click(self._back)
        except:
            self.click(self._buysuccess)












































